const Koa = require('koa');
const compose = require('koa-compose');

const MD = require('./middleware/');
const service = require('./service')
const utils = require('./common/utils.js')


const port = 8082
const app = new Koa();

app.context.service = service;
app.context.utils = utils;

app.use(compose(MD));

app.on('error', (err, ctx) => {
	if (ctx) {
		ctx.body = {
			code: 9999,
			message: `程序错误：${err.message}`
		};
	}
})

app.listen(port, () => {
    // console.log(process.env.DB_PASSWORD);
    console.log(`API server listening on  http://127.0.0.1:${port}`);
});

